﻿@model CompareProductsModel
@{
    Layout = "_ColumnsTwo";

    //title
    Html.AddTitleParts(T("PageTitle.CompareProducts").Text);
    //page class
    Html.AppendPageCssClassParts("html-compare-products-page");
}
@{
    var columnWidth = "";
    if (Model.Products.Count > 0)
    {
        columnWidth = Math.Round((decimal)(90M / Model.Products.Count), 0).ToString() + "%";
    }


    var specificationAttributes = new List<ProductSpecificationModel>();
    foreach (var product in Model.Products)
    {
        foreach (var attribute in product.SpecificationAttributeModels)
        {
            if (specificationAttributes.FirstOrDefault(sa => sa.SpecificationAttributeId == attribute.SpecificationAttributeId) == null)
            {
                specificationAttributes.Add(attribute);
            }
        }
    }
}
<div class="page compare-products-page">
    <div class="page-title">
        <h1>@T("Products.Compare.Title")</h1>
    </div>
    <div class="page-body">
        @if (Model.Products.Count > 0)
        {
            <a href="#" onclick="setLocation('@Url.RouteUrl("ClearCompareList")')" class="clear-list">@T("Products.Compare.Clear")</a>
            <div class="table-wrapper">
                <table class="compare-products-table">
                    <tbody>
                        <tr class="remove-product">
                            <td class="empty">&nbsp;</td>
                            @foreach (var product in Model.Products)
                            {
                                <td style="width: @columnWidth;">
                                    <input type="button" value="@T("Common.Remove")" title="@T("Common.Remove")" class="button-2 remove-button" onclick="setLocation('@Url.RouteUrl("RemoveProductFromCompareList", new { productId = product.Id })')" />
                                </td>
                            }
                        </tr>
                        <tr class="product-picture">
                            <td class="empty">&nbsp;</td>
                            @foreach (var product in Model.Products)
                            {
                                <td style="width: @columnWidth;">
                                    <a class="picture" href="@Url.RouteUrl("Product", new { SeName = product.SeName })"><img alt="@product.DefaultPictureModel.AlternateText" src="@product.DefaultPictureModel.ImageUrl" title="@product.DefaultPictureModel.Title" /></a>
                                </td>
                            }
                        </tr>
                        <tr class="product-name">
                            <td>
                                <label>@T("Products.Compare.Name")</label>
                            </td>
                            @foreach (var product in Model.Products)
                            {
                                <td style="width: @columnWidth;">
                                    <a href="@Url.RouteUrl("Product", new { SeName = product.SeName })">@product.Name</a>
                                </td>
                            }
                        </tr>
                        <tr class="product-price">
                            <td>
                                <label>@T("Products.Compare.Price")</label>
                            </td>
                            @foreach (var product in Model.Products)
                            {
                                <td style="width: @columnWidth;">
                                    @product.ProductPrice.Price
                                </td>
                            }
                        </tr>
                        @if (Model.IncludeShortDescriptionInCompareProducts)
                        {
                            <tr class="short-description">
                                <td>
                                    <label>@T("Products.Compare.ShortDescription")</label>
                                </td>
                                @foreach (var product in Model.Products)
                                {
                                    <td style="width: @columnWidth;">
                                        @Html.Raw(product.ShortDescription)
                                    </td>
                                }
                            </tr>
                        }
                        @foreach (var specificationAttribute in specificationAttributes)
                        {
                            <tr class="specification">
                                <td>
                                    <label>@specificationAttribute.SpecificationAttributeName</label>
                                </td>
                                @foreach (var product in Model.Products)
                                {
                                    var foundProductSpec = product.SpecificationAttributeModels.FirstOrDefault(psa => psa.SpecificationAttributeId == specificationAttribute.SpecificationAttributeId);
                                                                
                                    <td style="width: @columnWidth;">
                                        @if (foundProductSpec != null)
                                        {
                                            if (string.IsNullOrEmpty(foundProductSpec.ColorSquaresRgb))
                                            {
                                                @Html.Raw(foundProductSpec.ValueRaw)
                                            }
                                            else
                                            {
                                                <div class="attribute-squares color-squares">
                                                    <span class="attribute-square-container" title="@Html.Raw(foundProductSpec.ValueRaw)">
                                                        <span class="attribute-square" style="background-color: @(foundProductSpec.ColorSquaresRgb);">&nbsp;</span>
                                                    </span>
                                                </div>
                                            }
                                        }
                                        else
                                        {
                                            <text>&nbsp;</text>
                                        }
                                    </td>
                                }
                            </tr>                    
                        }
                        @if (Model.IncludeFullDescriptionInCompareProducts)
                        {
                            <tr class="full-description">
                                <td>
                                    <label>@T("Products.Compare.FullDescription")</label>
                                </td>
                                @foreach (var product in Model.Products)
                                {
                                    <td style="width: @columnWidth;">
                                        @Html.Raw(product.FullDescription)
                                    </td>
                                }
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        }
        else
        {
            <div class="no-data">
                @T("Products.Compare.NoItems")
            </div>
        }
    </div>
</div>
